package com.hyy.controller;

import com.hyy.bean.MaskUser;
import com.hyy.service.UserService;
import com.hyy.service.serviceImpl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "EditUsermsgServlet",urlPatterns = "/editUsermsg")
public class EditUsermsgServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doPost(req,resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		MaskUser user = (MaskUser) req.getSession().getAttribute("user");
		String newPassword = (String) req.getParameter("password");
		String newUseraccount = req.getParameter("useraccount");

		MaskUser newuser = new MaskUser(user.getUserid(),newUseraccount,user.getUsername()
				,newPassword,0);
		UserService userService = new UserServiceImpl();
		userService.updateUser(newuser);

		req.getSession().setAttribute("user", newuser);
		resp.sendRedirect("jsp/usermsg.jsp");
	}
}
